
if("`c(os)'"=="Windows"){
	local tableSaveDir = "Tables\DiD\"
	local plotSaveDir = "Plots\Bacon\"
	local dataSaveDir = "Data\"
	local pythonSaveDir = "PythonScripts\"
}
else{
	local tableSaveDir = "Tables/DiD/"
	local plotSaveDir = "Plots/Bacon/"
	local dataSaveDir = "Data/"
	local pythonSaveDir = "PythonScripts/"
}

do LoadDataBacon

//Establish Control Variable Sets
local Spec1Controls = "ib51.stateGroup ib1995.year c.normYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage"
local Spec2Controls = "`Spec1Controls' i.transactionDataDummy"
local Spec3Controls = "`Spec2Controls' i.regDummyExtSpec3"
local Spec4Controls = "`Spec2Controls' i.regDummyExtSpec4"


//Establish Cluster Variable
local clusterVar = "stateGroup"

//Create actual variable data for transaction data dummies and state-time trends
tab transactionDataDummy, gen(td)
local numTD = r(r)
tab stateGroup, gen(tt)
local numTT = r(r)
tab stateGroup, gen(qt)

forvalues i = 1(1)`numTT'{
	qui replace tt`i' = tt`i'*year
	qui replace qt`i' = qt`i'*year*year
}

//Establish specs
local newSpec2Controls = "asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage td1-td`numTD' tt1-tt`numTT' qt1-qt`numTT'"

//Set variables using xtset
xtset stateGroup year 

//Run edited Goodman-Bacon decomposition code to remove bug for current ssc install
do bacondecomp2

//Run bacon decomposition
bacondecomp2 logregistrations nosafetyind `newSpec2Controls' coDum1 coDum2, stub(bacReg) vce(cluster `clusterVar') gropt(title("Log Registration Goodman-Bacon Decomposition"))
ereturn list
graph export "`plotSaveDir'LogRegistrations.png", replace
bacondecomp2 logvmt nosafetyind `newSpec2Controls', stub(bacVMT) vce(cluster `clusterVar')  gropt(title("Log VMT Goodman-Bacon Decomposition"))
graph export "`plotSaveDir'LogVMT.png", replace
bacondecomp2 loghighwaygasuse nosafetyind `newSpec2Controls', stub(bacGas) vce(cluster `clusterVar')  gropt(title("Log Highway Gas Use Goodman-Bacon Decomposition"))
graph export "`plotSaveDir'LogGasUse.png", replace

//Save data
save "`dataSaveDir'baconData", replace
export delimited "`dataSaveDir'baconData.csv", replace

//Create plots for Goodman-Bacon Analysis
python script "`pythonSaveDir'PlotBacon.py"
